<template>
	<view class="page">
		<view class="head-back">
			<view class="back" @click="onBack">
				<text></text>
			</view>
			<view class="title">
				<text>我的订单</text>
			</view>
			<view class="more-icon">
				<view class="icon-list">
					<text class="iconfont icon-fadajing"></text>
				</view>
			</view>
		</view>
		<!-- 订单tab -->
		<view class="order-tab">
			<view class="tab" :class="{'action':OrderType==''}" @click="onOrderTab('')">
				<text>全部</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==0}" @click="onOrderTab(0)">
				<text>待付款</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==1}" @click="onOrderTab(1)">
				<text>待发货</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==2}" @click="onOrderTab(2)">
				<text>待收货</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==3}" @click="onOrderTab(3)">
				<text>待评价</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="order-list">
			<view class="list" v-for="(item,index) in orderList" @click="onOrderList" :key="index">
				<view class="title-status">
					<view class="title">
						<text>下单时间：{{item.create_time}}</text>
					</view>
					<view class="status">
						<text v-if="OrderType==2">待收货</text>
						<text v-else>待付款</text>
						<text class="iconfont icon-laji del"></text>
					</view> 
				</view>
				<view class="goods-list" v-for="(value,key) in item.orderGoodsInfo">
					<view class="goods">
						<view class="thumb">
							<image :src="value.goods_img" mode=""></image>
						</view>
						<view class="item">
							<view class="goods-name">
								<text class="two-omit">{{value.goods_info}}</text>
							</view>
							<view class="goods-price">
								<text class="min">￥</text>
								<text class="max">{{value.pay_postage}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="status-btn">
					<view class="btn">
						<text v-if="OrderType==2" @click.stop="onlogistics(item.id)" >查看物流</text>
						<text v-else>取消订单</text>
					</view>
					<view class="btn action" @click.stop="onEvaluate">
						<text>评价</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				OrderType: 0,
				orderList:[]
			};
		},
		onLoad(params) {
			uni.showLoading({title: '加载中',mask:true});
			this.OrderType = params.type;
			this.$http.get('order/status', {
				orders_status_code:params.type
			},{}).then(res => {
				if(res.data.data.length >0){
					this.orderList = res.data.data
					setTimeout(function () {uni.hideLoading();}, 100);
				}else{
					setTimeout(function () {uni.hideLoading();}, 100);
					uni.showToast({
					    title: "没有您要找的数据",
					    duration: 2000,
						icon:"none"
					});
				}
				
			})
		},
		methods:{
			/**
			 * 返回点击
			 */
			onBack(){
				uni.navigateBack();
			},
			/**
			 * 订单tab点击
			 */
			onOrderTab(type){
				var that = this
				this.OrderType = type;
				// #ifdef H5
				uni.redirectTo({
					url: '/pages/MyOrderList/MyOrderList?type=' + type,
				})
				//#endif
				
				this.$http.get('order/status', {
					orders_status_code:type
				},{}).then(res => {
					that.orderList = res.data.data
				})
			},
			/**
			 * 订单列表点击 
			 */
			onOrderList(){
				uni.navigateTo({
					url: '/pages/OrderDetails/OrderDetails',
				})
			},
			  /**
			   * 评价点击
			   */
			  onEvaluate(){
					  uni.navigateTo({
				  url: '/pages/MyEvaluatePush/MyEvaluatePush'
				})
			  },
			  
			  onlogistics(order_id){
				console.log(order_id)
				this.$http.post('expressLocusFree', {
					order_id:order_id
				},{}).then(res => {
					if(res.data.data.success == true){
						uni.navigateTo({
							url:"/pages/logistics/logistics?src=" + res.data.data.traceMapR
						})
					}
				})
			  }
		}
	}
</script>

<style scoped lang="scss">
	@import 'MyOrderList.scss';
</style>
